<template>
  <div class="dashboard-container">
    <div class="metric-container">
      <el-card class="metric-card">
        <div class="metric-icon">
          <i class="el-icon-document" />
        </div>
        <div class="metric-text">
          <span>总订单</span>
          <p>{{ totalOrders }}</p>
        </div>
      </el-card>
      <el-card class="metric-card">
        <div class="metric-icon">
          <i class="el-icon-money" />
        </div>
        <div class="metric-text">
          <span>总销售额</span>
          <p>{{ totalSales }}</p>
        </div>
      </el-card>
      <el-card class="metric-card">
        <div class="metric-icon">
          <i class="el-icon-s-order" />
        </div>
        <div class="metric-text">
          <span>今日订单数</span>
          <p>{{ todayOrders }}</p>
        </div>
      </el-card>
      <el-card class="metric-card">
        <div class="metric-icon">
          <i class="el-icon-money" />
        </div>
        <div class="metric-text">
          <span>今日销售额</span>
          <p>{{ todaySales }}</p>
        </div>
      </el-card>
    </div>
    <div id="chart-container"></div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import * as echarts from 'echarts';

// 模拟数据
const totalOrders = ref('102,400');
const totalSales = ref('102,400');
const todayOrders = ref('102,400');
const todaySales = ref('102,400');

onMounted(() => {
  // 初始化 ECharts 图表
  const chartDom = document.getElementById('chart-container');
  if (!chartDom) {
    console.error('Failed to find chart container');
    return;
  }

  const myChart = echarts.init(chartDom);
  const option = {
    title: {
      text: '数据统计'
    },
    tooltip: {
      trigger: 'axis'
    },
    legend: {
      data: ['订单', '销售额', '注册人数', '管理员人数']
    },
    xAxis: {
      type: 'category',
      data: ['2019/10/18', '2019/10/18', '2019/10/18', '2019/10/18', '2019/10/18', '2019/10/18', '2019/10/18']
    },
    yAxis: {
      type: 'value'
    },
    series: [
      {
        name: '订单',
        type: 'line',
        data: [1000, 1000, 800, 1600, 1200, 1200, 1000]
      },
      {
        name: '销售额',
        type: 'line',
        data: [1000, 1000, 800, 1600, 1200, 1200, 1000]
      },
      {
        name: '注册人数',
        type: 'line',
        data: [100, 150, 120, 130, 140, 150, 180]
      },
      {
        name: '管理员人数',
        type: 'line',
        data: [50, 50, 50, 50, 50, 50, 50]
      }
    ]
  };

  myChart.setOption(option);
});
</script>

<style scoped>
.dashboard-container {
  padding: 10px;
}

.metric-container {
  display: flex;
  justify-content: space-around;
  margin-bottom: 20px;
}

.metric-card {
  width: 200px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.metric-icon {
  font-size: 24px;
  margin-bottom: 10px;
  color: #409eff; /* 设置图标颜色 */
}

.metric-text {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.metric-text span {
  font-weight: bold;
  margin-bottom: 5px;
}

#chart-container {
  width: 100%;
  height: 400px;
}
</style>
